package cc.rengu.igas.bsps.common.util;

import cc.rengu.igas.bsps.common.dao.BspsUserInfoMapper;
import cc.rengu.igas.bsps.common.dao.impl.BspsUserInfoMapperImpl;
import cc.rengu.igas.bsps.common.entity.UserInfo;
import cc.rengu.oltp.service.common.enums.PinTypeEnum;
import cc.rengu.oltp.service.model.PasswordInfo;
import cc.rengu.oltp.service.realize.SafeKeyBoardService;
import cc.rengu.oltp.service.realize.impl.SafeKeyBoardServiceImpl;
import cc.rengu.oltp.utility.util.StringUtil;

/**
 * Created by zhangxuran on
 */
public class TransPasswordCheckUtil {

    public static boolean checkPassword(String instId, String userId, String passwordKey) throws Exception {
        boolean checkFlag = false;
        String password;
        SafeKeyBoardService safeKeyBoardService = new SafeKeyBoardServiceImpl();
        PasswordInfo passwordInfo = new PasswordInfo(userId, PinTypeEnum.DIGITAL, passwordKey);
        password = safeKeyBoardService.encryptPassword(instId, null, passwordInfo, null);
        BspsUserInfoMapper bspsUserInfoMapper = new BspsUserInfoMapperImpl();
        UserInfo userInfo = bspsUserInfoMapper.selectBspsUserInfoByUserId(instId, userId);
        if (null == userInfo) {
            return checkFlag;
        }
        if (StringUtil.isEmptyOrNull(userInfo.getTransPassword()) && password.equals(userInfo.getTransPassword())) {
            checkFlag = true;
        }
        return checkFlag;
    }
}
